<template>
  <div>
    <table>
      <tr>
        <td> id</td>
        <td>商品名称</td>
        <td>分类名称</td>
        <td>操作</td>
      </tr>
      <tr v-for="i in shop">
        <td><input type="checkbox" :value="i.id" v-model="list1"> {{ i.id }}</td>
        <td>{{ i.name }}</td>
        <td>
          <van-button @click="getshop1(i.cid)">{{ i.cname }}</van-button>
        </td>
        <td>
          <button @click="del(i.id)">删除</button>
        </td>
      </tr>
      <tr>
        <td>
          <van-button @click="delall(list1)">删除选中</van-button>
        </td>
      </tr>
    </table>
    <button v-for="i in tpage" @click="getshop(i)">{{ i }}</button>
  </div>
</template>

<script>
export default {
  name: "qshop",
  data() {
    return {
      shop: [],
      tpage: 0,
      cpage: 1,
      list1: []
    }
  },
  methods: {
    getshop(i) {
      this.cpage = i
      this.$axios.get('/qcate/shop?cpage=' + this.cpage)
        .then(res => {
          this.shop = res.data.list
          this.tpage = res.data.total

        })
    },
    getshop1(id) {
      this.$axios.get('/qcate/shop1?id=' + id)
        .then(res => {
          if (res.data.code == 200) {
            this.shop = res.data.list
          }
        })

    },
    delall(list) {
      this.$axios.delete('/qcate/shop1?list=' + this.list1)
        .then(res => {
          if (res.data.code == 200) {
            alert('删除成功')
            this.getshop(1)
          }
        })

    },
    del(id) {
      this.$axios.delete('/qcate/shop?id=' + id)
        .then(res => {
          if (res.data.code == 200) {
            alert('删除成功')
            this.getshop(1)
          }
        })
    }
  },
  mounted() {
    this.getshop(1)

  }
}
</script>

<style scoped>

</style>
